

// 代理服务

const TARGET = 'http://www.cq315house.com'

var express = require('express')
var proxy = require('http-proxy-middleware')

var app = express()


function getDate(){
  const date = new Date()
  return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDay()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
}

var allowCrossDomain = function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')//自定义中间件，设置跨域需要的响应头。
  console.log(`${getDate()}:${req.headers['x-real-ip']},${req.headers['user-agent']}`)
  next()
}

app.use(allowCrossDomain)//运用跨域的中间件
 
app.use('/', proxy({ target: TARGET, changeOrigin: true }))

app.listen(3000)